<?php
session_start();

if(!empty($_POST['nickname']) && !empty($_POST['topic'])){
	//创建全局变量
	$_SESSION['user'] = $_POST['nickname'];
	$_SESSION['topic'] = $_POST['topic'];
	if(!empty($_SESSION['user'])){
		header("Location:http://".$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['PHP_SELF']),'/\\')."/"."main.php");
	}else{
		echo "<script>alert('请输入正确的昵称');</script>";
		exit();
	}
}else{
	unset($_SESSION['user']);
	session_destroy();
}


?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>聊天室引导页</title>
</head>

<body>
<style>
body{padding:10px;}
</style>
<h1>欢迎来到PHP聊天室</h1>

<form action="index.php" method="post" name="f1">
	<label>请输入昵称：</label><input type="text" name="nickname" /><br />
	<label>请选择聊天主题：</label>
	<select name="topic">
		<option value=""></option>
		<option value="金融聚焦" selected="selected">金融聚焦</option>
		<option value="股市风云">股市风云</option>
		<option value="保险基金">保险基金</option>
		<option value="精英理财">精英理财</option>
		<option value="情感都市">情感都市</option>
	</select><br />
	<input type="submit" value="进入聊天室" />

</form>

</body>
</html>
